package com.info33.platform.common.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * @author debj
 * @version 1.0
 * @date 2021/7/14 9:53
 */
public enum FileSuffixEnum {

    /**
     * 视频
     */
    VIDEO,

    /**
     * 图片
     */
    IMG,

    /**
     * 文件
     */
    FILE,

    /**
     * 其它
     */
    OTHERS;

    public static final String DIAN = ".";
    public static final String SLASH = "/";
    public static final String PNG_SUFFIX = "png";
    public static final String MOV_SUFFIX = "mov";
    public static final String MP_4_SUFFIX = "mp4";
    public static final String PPT_SUFFIX = "ppt";
    public static final String PPTX_SUFFIX = "pptx";
    public static final String PDF = "pdf";

    /**
     * 视频后缀分组集合
     */
    private static final Map<String, FileSuffixEnum> GROUP_MAP;

    static {
        GROUP_MAP = new HashMap<>();
        GROUP_MAP.put(MP_4_SUFFIX, VIDEO);
        GROUP_MAP.put(MOV_SUFFIX, VIDEO);
        GROUP_MAP.put(MOV_SUFFIX.toUpperCase(), VIDEO);

        GROUP_MAP.put(PNG_SUFFIX, IMG);
        GROUP_MAP.put("jpg", IMG);
        GROUP_MAP.put("jpeg", IMG);
        GROUP_MAP.put("gif", IMG);
        GROUP_MAP.put("webp", IMG);

        GROUP_MAP.put("zip", FILE);
        GROUP_MAP.put("word", FILE);
        GROUP_MAP.put("txt", FILE);
        GROUP_MAP.put("jar", FILE);
        GROUP_MAP.put(PPT_SUFFIX, FILE);
        GROUP_MAP.put(PPTX_SUFFIX, FILE);
        GROUP_MAP.put(PDF,FILE);
    }

    /**
     * 根据后缀，返回对应的文件后缀枚举
     *
     * @param suffix 后缀
     * @return 枚举对象
     */
    public static FileSuffixEnum getSuffixGroup(String suffix) {
        if (GROUP_MAP.containsKey(suffix)) {
            return GROUP_MAP.get(suffix);
        }
        return OTHERS;
    }

}